//
//  ActivityViewController.m
//  RainbowFM
//
//  Created by chenli on 14/12/10.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "ActivityViewController.h"
#import "UtilsCell.h"
#import "ActivityModel.h"
#import "ActivityDetailController.h"



@interface ActivityViewController (){
    NSMutableArray *listArray;
}

@end

@implementation ActivityViewController

-(void)fetchListData{
    [listArray removeAllObjects];
    [[ActivityModel sharedModel] fetchActivityListWithPage:1 result:^(BOOL success, NSArray *array) {
        [listArray addObjectsFromArray:array];
        [self.tableView reloadData];
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    listArray = [NSMutableArray array];
    [self fetchListData];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return listArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ActivityListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ActivityListCell" forIndexPath:indexPath];
    ActivityListItem *item = listArray[indexPath.row];
    
    cell.titleLabel.text = item.actName;
    cell.desLabel.text = [NSString stringWithFormat:@"报名时间:\n%@ 至 %@",item.startTime,item.endTime];
    [cell.cellImageView sd_setImageWithURL:[NSURL URLWithString:item.pic]];
    return cell;
}


#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
    
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    ActivityListItem *item = listArray[indexPath.row];
    
    [[segue destinationViewController] setActId:item.actId];
}


@end
